<html>
<head><meta charset="utf-8"><title>Hiding ManuallyDrop from LLVM? · t-compiler/wg-llvm · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/187780-t-compiler/wg-llvm/index.html">t-compiler/wg-llvm</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/187780-t-compiler/wg-llvm/topic/Hiding.20ManuallyDrop.20from.20LLVM.3F.html">Hiding ManuallyDrop from LLVM?</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="219535104"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187780-t-compiler/wg-llvm/topic/Hiding%20ManuallyDrop%20from%20LLVM%3F/near/219535104" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> scottmcm <a href="https://rust-lang.github.io/zulip_archive/stream/187780-t-compiler/wg-llvm/topic/Hiding.20ManuallyDrop.20from.20LLVM.3F.html#219535104">(Dec 10 2020 at 21:17)</a>:</h4>
<p>Context: Using <code>ManuallyDrop</code> causes <code>alloca</code>s and <code>memcpy</code>s that LLVM cannot remove, <a href="https://github.com/rust-lang/rust/issues/79914">https://github.com/rust-lang/rust/issues/79914</a></p>
<p>Since you folks know more about LLVM than I do, does this seem like something that should be fixed in Mir-&gt;LLVM or in LLVM itself (or would somewhere else be better)?</p>
<p>I was pondering if I should try making the <code>%"std::mem::ManuallyDrop&lt;_&gt;"</code> types never show up in the LLVM output, for example, to try to make the <code>alloca</code>s easier to remove, as there'd be need to SRoA them first, hopefully.  (Or maybe even do that for <em>all</em> <code>repr(transparent)</code> type?)</p>



<a name="219539232"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187780-t-compiler/wg-llvm/topic/Hiding%20ManuallyDrop%20from%20LLVM%3F/near/219539232" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> cuviper <a href="https://rust-lang.github.io/zulip_archive/stream/187780-t-compiler/wg-llvm/topic/Hiding.20ManuallyDrop.20from.20LLVM.3F.html#219539232">(Dec 10 2020 at 21:55)</a>:</h4>
<p>it seems weird for debuginfo at least, if <code>ManuallyDrop</code> or other transparent wrappers are absent</p>



<a name="219547769"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187780-t-compiler/wg-llvm/topic/Hiding%20ManuallyDrop%20from%20LLVM%3F/near/219547769" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> scottmcm <a href="https://rust-lang.github.io/zulip_archive/stream/187780-t-compiler/wg-llvm/topic/Hiding.20ManuallyDrop.20from.20LLVM.3F.html#219547769">(Dec 10 2020 at 23:19)</a>:</h4>
<p>I don't know much about metadata -- how much does the type name in the IR matter, vs the <code>!DICompositeType</code> metadata?</p>



<a name="219549945"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187780-t-compiler/wg-llvm/topic/Hiding%20ManuallyDrop%20from%20LLVM%3F/near/219549945" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> cuviper <a href="https://rust-lang.github.io/zulip_archive/stream/187780-t-compiler/wg-llvm/topic/Hiding.20ManuallyDrop.20from.20LLVM.3F.html#219549945">(Dec 10 2020 at 23:48)</a>:</h4>
<p>I don't know</p>



<a name="220062857"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187780-t-compiler/wg-llvm/topic/Hiding%20ManuallyDrop%20from%20LLVM%3F/near/220062857" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> pnkfelix <a href="https://rust-lang.github.io/zulip_archive/stream/187780-t-compiler/wg-llvm/topic/Hiding.20ManuallyDrop.20from.20LLVM.3F.html#220062857">(Dec 16 2020 at 00:19)</a>:</h4>
<p><span class="user-mention" data-user-id="125270">@scottmcm</span> I'd be curious to know the scope of this problem. Is it truly something originating from <code>ManuallyDrop</code> alone? Or is it an artifact of some other aspect of <code>ManuallyDrop</code>, such as (as you may be pointing out), <code>#[repr(transparent)]</code>. (Which would be weird, but who knows.)</p>



<a name="220064374"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187780-t-compiler/wg-llvm/topic/Hiding%20ManuallyDrop%20from%20LLVM%3F/near/220064374" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> scottmcm <a href="https://rust-lang.github.io/zulip_archive/stream/187780-t-compiler/wg-llvm/topic/Hiding.20ManuallyDrop.20from.20LLVM.3F.html#220064374">(Dec 16 2020 at 00:39)</a>:</h4>
<p><span class="user-mention" data-user-id="116083">@pnkfelix</span> As you say, I think it's a problem with anything where one needs a by-value newtype.  If it didn't need by-value then I could just do pointer-casts, but for moving out of things I couldn't find a way to hack around it.</p>
<p>And it's also a problem for other things, but those would be much harder to solve -- for example <code>array::IntoIter</code> can be awkward to use to consume an array parameter because it copies the whole contents into the local, but that one does need the extra state so I wanted to try to limit the bug to the simpler case for now.</p>



<a name="220065097"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187780-t-compiler/wg-llvm/topic/Hiding%20ManuallyDrop%20from%20LLVM%3F/near/220065097" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> scottmcm <a href="https://rust-lang.github.io/zulip_archive/stream/187780-t-compiler/wg-llvm/topic/Hiding.20ManuallyDrop.20from.20LLVM.3F.html#220065097">(Dec 16 2020 at 00:49)</a>:</h4>
<p>Said otherwise, it might be a problem for any <code>T</code> where the ABI "by value" passing passes it as a <code>T*</code>.</p>



<a name="220065130"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187780-t-compiler/wg-llvm/topic/Hiding%20ManuallyDrop%20from%20LLVM%3F/near/220065130" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> scottmcm <a href="https://rust-lang.github.io/zulip_archive/stream/187780-t-compiler/wg-llvm/topic/Hiding.20ManuallyDrop.20from.20LLVM.3F.html#220065130">(Dec 16 2020 at 00:49)</a>:</h4>
<p>Hopefully NRVO will be able to optimize it out for <code>_0</code>, at least.</p>



<a name="220067468"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187780-t-compiler/wg-llvm/topic/Hiding%20ManuallyDrop%20from%20LLVM%3F/near/220067468" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nagisa <a href="https://rust-lang.github.io/zulip_archive/stream/187780-t-compiler/wg-llvm/topic/Hiding.20ManuallyDrop.20from.20LLVM.3F.html#220067468">(Dec 16 2020 at 01:24)</a>:</h4>
<p>We could have a peephole MIR optimisation somewhere late in the pipeline that just replaces #[repr(transparent)] types with their contents</p>



<a name="220067491"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187780-t-compiler/wg-llvm/topic/Hiding%20ManuallyDrop%20from%20LLVM%3F/near/220067491" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nagisa <a href="https://rust-lang.github.io/zulip_archive/stream/187780-t-compiler/wg-llvm/topic/Hiding.20ManuallyDrop.20from.20LLVM.3F.html#220067491">(Dec 16 2020 at 01:25)</a>:</h4>
<p>but overall yeah the problem is more general</p>



<a name="220067565"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187780-t-compiler/wg-llvm/topic/Hiding%20ManuallyDrop%20from%20LLVM%3F/near/220067565" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nagisa <a href="https://rust-lang.github.io/zulip_archive/stream/187780-t-compiler/wg-llvm/topic/Hiding.20ManuallyDrop.20from.20LLVM.3F.html#220067565">(Dec 16 2020 at 01:26)</a>:</h4>
<p>ABI is in an interesting spot here because by-val types if passed by pointer are still byval</p>



<a name="220067587"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187780-t-compiler/wg-llvm/topic/Hiding%20ManuallyDrop%20from%20LLVM%3F/near/220067587" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nagisa <a href="https://rust-lang.github.io/zulip_archive/stream/187780-t-compiler/wg-llvm/topic/Hiding.20ManuallyDrop.20from.20LLVM.3F.html#220067587">(Dec 16 2020 at 01:27)</a>:</h4>
<p>that is, there must be a copy somewhere so that caller mutating the… pointer, wouldn't mutate the actual original value.</p>



<a name="220067682"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187780-t-compiler/wg-llvm/topic/Hiding%20ManuallyDrop%20from%20LLVM%3F/near/220067682" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nagisa <a href="https://rust-lang.github.io/zulip_archive/stream/187780-t-compiler/wg-llvm/topic/Hiding.20ManuallyDrop.20from.20LLVM.3F.html#220067682">(Dec 16 2020 at 01:29)</a>:</h4>
<p>by value arguments, esp. the larger ones, rely on inlining more than anything else to achieve any semblance of efficiency.</p>



<a name="220081229"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187780-t-compiler/wg-llvm/topic/Hiding%20ManuallyDrop%20from%20LLVM%3F/near/220081229" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> scottmcm <a href="https://rust-lang.github.io/zulip_archive/stream/187780-t-compiler/wg-llvm/topic/Hiding.20ManuallyDrop.20from.20LLVM.3F.html#220081229">(Dec 16 2020 at 06:13)</a>:</h4>
<p><span class="user-mention silent" data-user-id="123586">nagisa</span> <a href="#narrow/stream/187780-t-compiler.2Fwg-llvm/topic/Hiding.20ManuallyDrop.20from.20LLVM.3F/near/220067587">said</a>:</p>
<blockquote>
<p>that is, there must be a copy somewhere so that caller mutating the… pointer, wouldn't mutate the actual original value.</p>
</blockquote>
<p>Moving out isn't a mutation, though, right?  So at least for the <code>[T; N]</code> -&gt; <code>ManuallyDrop&lt;[T; N]&gt;</code> -&gt; move-out-items use it feels like it shouldn't need a copy, and could just use the ABI value directly.</p>



<a name="220097438"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187780-t-compiler/wg-llvm/topic/Hiding%20ManuallyDrop%20from%20LLVM%3F/near/220097438" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> tm <a href="https://rust-lang.github.io/zulip_archive/stream/187780-t-compiler/wg-llvm/topic/Hiding.20ManuallyDrop.20from.20LLVM.3F.html#220097438">(Dec 16 2020 at 10:10)</a>:</h4>
<p>Currently the code generation for byval types, using indirect ABI, and passed with <code>Operand::Move</code>, will avoid copy and possibly mutate them in place. At the same time, the built MIR will likely contain a temporary copy before the call, like in the original example.</p>



<a name="220581245"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187780-t-compiler/wg-llvm/topic/Hiding%20ManuallyDrop%20from%20LLVM%3F/near/220581245" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/187780-t-compiler/wg-llvm/topic/Hiding.20ManuallyDrop.20from.20LLVM.3F.html#220581245">(Dec 21 2020 at 13:06)</a>:</h4>
<p><span class="user-mention" data-user-id="125270">@scottmcm</span> </p>
<blockquote>
<p>Moving out isn't a mutation, though, right?</p>
</blockquote>
<p>Well, <a href="#narrow/stream/136281-t-lang.2Fwg-unsafe-code-guidelines/topic/Use-after-move">some people are proposing to make it a mutation</a> ;)</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>